package cn.mxz.xmu.restful.service;

import net.sf.json.JSONArray;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import wang.mouge.cache.client.DeprecatedRedisLibrary;

/**
 * 处理学校信息门户及其他学校相关的功能的转发器
 * 
 * @author dongchao <dongchao@mouge.wang>
 * @since 2015-08-07
 */
@Scope("prototype")
@Component
public class UniversityService
{
	public String param(String method, String schoolId, String term, String day, String xiaoquId, String louId)
	{
		String data = null;
		switch (method)
		{
		case "emptyClassroom":
			JSONArray emptyArray = JSONArray.fromObject(DeprecatedRedisLibrary.hget(schoolId, "emptyroom" + term));
			JSONArray xiaoquArray = JSONArray.fromObject(emptyArray.getJSONObject(Integer.parseInt(day) - 1).get("xiaoqu"));
			for (int i = 0; i < xiaoquArray.size(); i++)
			{
				if (xiaoquArray.getJSONObject(i).get("xiaoquId").equals(xiaoquId))
				{
					JSONArray louArray = JSONArray.fromObject(xiaoquArray.getJSONObject(i).get("lou"));
					for (int j = 0; j < louArray.size(); j++)
					{
						if (louArray.getJSONObject(j).get("louId").equals(louId) && (JSONArray.fromObject(louArray.getJSONObject(j).get("classRoom")) != null))
						{
							JSONArray classArray = JSONArray.fromObject(louArray.getJSONObject(j).get("classRoom"));
							data = classArray.toString();
						}
					}
				}
			}
			break;
		case "campusBuilding":
			data = DeprecatedRedisLibrary.hget(schoolId, method);
			break;
		}
		return data;
	}
}
